unit uFrmConsultor;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, uCadPadrao, StdCtrls, Mask, DBCtrls, DB, ActnList, ImgList, Buttons,
  ExtCtrls, ComCtrls, Contnrs , uDM1, uClasses;

type
  TFrmConsultor = class(TFrmCadPadrao)
    Label1: TLabel;
    DBEdit1: TDBEdit;
    Label2: TLabel;
    DBEdit2: TDBEdit;
    Label3: TLabel;
    DBEdit3: TDBEdit;
    Label4: TLabel;
    DBEdit4: TDBEdit;
    Label5: TLabel;
    DBLookupComboBox1: TDBLookupComboBox;
    DS2: TDataSource;
    ColorBox1: TColorBox;
    Label6: TLabel;
    procedure AInserirExecute(Sender: TObject);
    procedure APesquisarExecute(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure AImprimirExecute(Sender: TObject);
    procedure DS1DataChange(Sender: TObject; Field: TField);
    procedure ASalvarExecute(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FrmConsultor: TFrmConsultor;

implementation

uses uFrmPesquisaPadrao2, uClassesPesquisa;


{$R *.dfm}

procedure TFrmConsultor.AImprimirExecute(Sender: TObject);
begin
  inherited;
  TFuncoes.AbrirImpressosAcao('CONSULTOR',DS1.DataSet.FieldByName('COD_CONSULTOR').AsString);
end;

procedure TFrmConsultor.AInserirExecute(Sender: TObject);
begin
  inherited;
  DS1.DataSet.FieldByName('COD_CONSULTOR').AsInteger := DM1.ObterCodGenerator('COD_CONSULTOR');
  DS1.DataSet.FieldByName('ATIVO_CONSULTOR').AsString := 'T';
end;

procedure TFrmConsultor.APesquisarExecute(Sender: TObject);
begin
  inherited;
  {if not Assigned(FrmPesquisaPadrao2) then
  begin
    Application.CreateForm(TFrmPesquisaPadrao2,FrmPesquisaPadrao2);
    FrmPesquisaPadrao2.Pesquisa.Tabela := 'CONSULTOR';
    FrmPesquisaPadrao2.Pesquisa.TabelaApelido := 'CON';
    FrmPesquisaPadrao2.Pesquisa.CampoRetorno := 'COD_CONSULTOR';
    FrmPesquisaPadrao2.Pesquisa.FormPesquisa := FrmPesquisaPadrao2;
    FrmPesquisaPadrao2.Pesquisa.CaptionFormPesquisa := 'Pesquisa - Consultor';
  end;
  FrmPesquisaPadrao2.ShowModal;
  if not VarIsEmpty(FrmPesquisaPadrao2.Pesquisa.CodRetorno) then
  begin
    DS1.DataSet.Close;
    with DM1.sdsConsultor do
    begin
      Close;
      CommandText := 'select * from consultor where cod_consultor = ' + QuotedStr(FrmPesquisaPadrao2.Pesquisa.CodRetorno);
      Open;
    end;
    DS1.DataSet.Open;

  end;}
  TFuncoesPesquisa.CriarFormPesquisa('CONSULTOR','CON','COD_CONSULTOR','Pesquisa - CONSULTOR');
  TFuncoes.PesquisaPadraoForm(FrmPesquisaPadrao2.Pesquisa , DS1 ,DM1.sdsConsultor);


end;

procedure TFrmConsultor.ASalvarExecute(Sender: TObject);
begin
  DS1.DataSet.FieldByName('COR_LEGENDA_CONSULTOR').AsString := ColorToString(ColorBox1.Selected);
  inherited;
end;

procedure TFrmConsultor.DS1DataChange(Sender: TObject; Field: TField);
begin
  inherited;
    if DS1.State = dsInsert then
  begin
    ColorBox1.Selected := clBlack;
  end
  else
  begin
    if DS1.DataSet.FieldByName('COR_LEGENDA_CONSULTOR').IsNull then
      ColorBox1.Selected := clBlack
    else
      ColorBox1.Selected := StringToColor(DS1.DataSet.FieldByName('COR_LEGENDA_CONSULTOR').AsString);
  end;
  ColorBox1.Enabled := (DS1.State in [dsInsert,dsEdit]);
end;

procedure TFrmConsultor.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  inherited;
  //if Assigned(FrmPesquisaPadrao2) then FreeAndNil(FrmPesquisaPadrao2);
  DM1.sdsConsultor.Close;
  DM1.cdsConsultor.Close;
  DM1.sdsConsultor.CommandText := 'select first 0 * from consultor';
end;

procedure TFrmConsultor.FormCreate(Sender: TObject);
begin
  DM1.sdsConsultor.Open;
  DM1.cdsConsultor.Open;
  inherited;

end;

end.
